<template>
  <div class="login-container">
    <div>
      <h2 class="title">{{ title }}</h2>
    </div>
    <div class="iptbox">
      <img src="@/assets/img/icon_dl_sjh.png" class="ipticon1">
      <input placeholder="请输入手机号" class="ipt" v-model="phone">
    </div>
    <div class="iptbox">
      <img src="@/assets/img/icon_zc_yzm.png" class="ipticon2">
      <input placeholder="请输入验证码" class="ipt" v-model="yanzhengma">
      <div class="yanzhengbox" v-if="yanzheng == 0" @click="tohave"><span>获取验证码 </span></div>
      <div class="yanzhengbox" v-if="yanzheng == 1"><span> {{ count }}后重新获取验证码 </span></div>
    </div>
    <div class="iptbox">
      <img src="@/assets/img/icon_dl_mm.png" class="ipticon2">
      <input placeholder="请输入登录密码" class="ipt" v-model="password" type="password">
    </div>
    <div class="iptbox">
      <img src="@/assets/img/icon_dl_mm.png" class="ipticon2">
      <input placeholder="再次输入登录密码" class="ipt" v-model="password2" type="password">
    </div>
    <div class="loginbtn" @click="register">注册</div>
    <div class="loginbtn" style="background:#4b0" @click="tologin">已有账号</div>
    
  </div>
  
</template>
<script>
export default {
  data() {
    return {
      phone:'',
      password:'',
      password2:'',
      yanzhengma:'',
      title: "注册",
      yanzheng:0,
      reallyyanzhengma:'',
      count:60,
      timer:null
    };
  },
  methods: {
    register(){
      let that = this
      let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
      if(that.phone == '' || that.yanzhengma == '' || that.password == ''){
        that.$toast({
          message:"请完善信息"
        })
      }
      if (!myreg.test(that.phone)) {
        that.$toast({
          message:"请输入正确手机号"
        })
      }
      if(that.password !== that.password2){
        that.$toast({
          message:"密码不一致！"
        })
      }
      var Sukdata = {
        phone:that.phone,
        password:that.password,
        code:that.yanzhengma
        };
        // console.log(obj)
        that.axios.post(that.baseUrl + "/user/register",that.Qs.stringify(Sukdata), {
        headers: {
        "Content-Type": "application/x-www-form-urlencoded"
        }
        }).then(function(res) {
        if (res.request.status === 200) {
          console.log(res.data);
          if (res.data.meta.code == 200) {
            that.$toast.success({
          message:"注册成功！"
            })
            that.$router.push({
              name:'login'
            })
          }else if(res.data.meta.code == 501){
            that.$toast({
              message:res.data.meta.msg
            })
  
          }
        }
        });
    },
    tohave(){
      let that = this;
      let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
      if (!myreg.test(that.phone)) {
        that.$toast({
          message:"请输入正确手机号"
        })
        return false;
      }else{
        let Sukdata = {
          phone:that.phone
        };
        that.axios.post(that.baseUrl + "/user/sendsmsLp",that.Qs.stringify(Sukdata), {
        headers: {
        "Content-Type": "application/x-www-form-urlencoded"
        }
        }).then(function(res) {
        if (res.request.status === 200) {
          console.log(res.data);
          if (res.data.meta.code == 200) {
          }else if(res.data.meta.code == 501){

          }
        }
        });


        const timer = setInterval(() =>{
        that.count--
        console.log(that.count)
        if(that.count == 0){
          clearInterval(timer)
          that.yanzheng = 0
          that.count = 60
        }
        },1000)
        that.count = 60
        that.yanzheng = 1
      }
    },
    toregister(){
      this.$router.push({
        name:"register"
      })
    },
    tologin(){
      this.$router.push({
        name:"login"
      })
    }
  }
};
</script>
<style scoped>
.login-other {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding-bottom: 30px;
}
.yanzhengbox{
  padding-left: 1%;
  padding-right: 1%;
  position: absolute;
  top: 23%;
  right: 5%;
  display: flex;
  align-items: center;
  text-align: center;
  justify-content: center;
  height: 50%;
  color: #ff2f4e;
  border-radius: 10px;
  border: 1px solid #ff2f4e
}
.loginbtn{
  width: 80%;
  margin-top: 15px;
  text-align: center;
  background: #ff2f4e;
  margin: 25px auto;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  border-radius: 8px
}
.other-model {
  margin-top: 30px;
  text-align: center;
}
.other-qq {
  display: flex;

  justify-content: center;
}
.other-img {
  width: 40%;
  margin-bottom: 10px;
}
.other-tip {
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  align-items: center;
  color: #8a8a8a;
}
.login-border {
  display: inline-block;
  height: 0;
  width: 34%;
  border-bottom: #e3e3e3 solid 1px;
}
.login-container {
  font-size: 0.3rem;
  height: 100%;
  width: 100%;
  position: fixed;
}
.title {
  padding-top: 20px;
}
.ipticon1 {
  width: 13px;
  height: 20px;
  vertical-align: middle;
  margin-left: 17px;
}
.iptbox {
  position: relative;
  width: 90%;
  /* height: 6%; */
  display: flex;
  align-items: center;
  border: 1px solid #dcdcdc;
  border-radius: 20px;
  margin: 20px auto;
  text-align: left;
}
.ipticon2 {
  width: 16px;
  margin-left: 17px;
  height: 20px;
  vertical-align: middle;
}
.ipt {
  border: none;
  color: #8a8a8a;
  height: 35px;
  margin-left: 12px;
}
h2 {
  text-align: center;
}
.bbox {
  width: 90%;
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
  color: #ff2f4e;
}
</style>
